import 'package:flutter/foundation.dart';
import 'package:loxen/mode/base_mode.dart';
import 'package:loxen/mode/inspiration/inspiration_page.dart';
import 'package:rxdart/rxdart.dart';
import 'package:loxen/api/api.dart';

mixin InspirationMixin {
  Stream<InspirationPage> userInspirationPage(
      {String userId = '0', String page = '1', String pageSize}) {
    return ApiService.userWorks(userId, page.toString(), pageSize)
        .flatMap(
            (value) => compute(decodeInspirationBean, value.data).asStream())
        .flatMap((value) => Stream.value(value.data));
  }

  static BaseMode<InspirationPage> decodeInspirationBean(dynamic json) {
    return BaseMode<InspirationPage>(json);
  }
}
